//
//  TZChooseColorView.m
//  SelectPhotosOrVideoContentViewLib
//
//  Created by Dubaoquan on 2019/10/29.
//

#import "TZChooseColorView.h"
#import "AppConst.h"

@interface TZChooseColorView()
@property(nonatomic,strong) NSArray *allColors;
@end

@implementation TZChooseColorView



-(instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
        for (NSInteger i=0; i<self.allColors.count; i++) {
  
            UIColor *color = self.allColors[i];
            CGFloat gap = 10,width =self.bounds.size.height-2*gap;
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.layer.cornerRadius = (self.bounds.size.height-2*gap)/2.0;
            button.layer.masksToBounds = YES;
            button.layer.borderColor = [UIColor whiteColor].CGColor;
            button.layer.borderWidth = 2;
            button.backgroundColor = color;
            button.frame = CGRectMake(gap+(gap+width)*i, gap, width, width);
            [button addTarget:self action:@selector(chooseColorAction:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = i;
            if (i==1) {
                button.titleLabel.font = [UIFont systemFontOfSize:14];
                [button setTitle:@"无" forState:UIControlStateNormal];
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }
            [self addSubview:button];
            self.contentSize = CGSizeMake(CGRectGetMaxX(button.frame)+gap, width+2*gap);
        }
    }
    return self;
}

-(void)chooseColorAction:(UIButton*)sender{

    if (self.colorDelegate) {
        [self.colorDelegate colorFromeTZChooseColorView:self.allColors[sender.tag]];
    }
    
}

-(NSArray*)allColors{

    if (!_allColors) {
        _allColors = @[[UIColor whiteColor],[UIColor clearColor],[UIColor blackColor],R_G_B_16(0xed5f59),R_G_B_16(0xaf35cf),R_G_B_16(0x545ace),R_G_B_16(0x4b97ee),R_G_B_16(0x79d375),R_G_B_16(0xf8cc45),R_G_B_16(0xf2974f),R_G_B_16(0x8ac5a7),R_G_B_16(0xf2b0a9),R_G_B_16(0x2b6a8e),R_G_B_16(0x32513e),R_G_B_16(0x92979e),R_G_B_16(0x32333),R_G_B_16(0x666666),R_G_B_16(0xe2473c),R_G_B_16(0x393dc9),R_G_B_16(0x69d4a4)];
    }
    return _allColors;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
